package com.sbcb.mongodb.controller;

import com.sbcb.mongodb.entity.Order;
import com.sbcb.mongodb.entity.OrderDataFactory;
import com.sbcb.mongodb.service.NativeMongoDBService;
import com.sbcb.mongodb.service.SpringbootMongoDBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mongodb")
public class MongoDBController {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    SpringbootMongoDBService springbootMongoDBService;

    @Autowired
    NativeMongoDBService nativeMongoDBService;

    //http://localhost:8080/mongodb/test
    @GetMapping("test")
    public String test(){
        return "Hello MongoDBController";
    }

    //http://localhost:8080/mongodb/saveOrders
    @GetMapping("saveOrders")
    public String saveOrders(){
        springbootMongoDBService.saveAll(OrderDataFactory.buildOrders());
//        for(Order order: OrderDataFactory.buildOrders()) {
//            mongoTemplate.save(order,"sbcb_orders");
//        }
        return "saved order list";
    }
}
